<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Copy a category incl. values but
 * without images
 * used from category.page.php
 * 
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
foreach ($_POST['marker'] as $idx)
{
	db::getInstance()->where("category_id", $idx);
	$categoryTopx = db::getInstance()->getOne("category");

	$result = db::getInstance()->rawQuery("SELECT count(*) FROM category " .
		"WHERE category_top ='" . $categoryTopx['category_top'] . "'");
	$count = $result[0]['count(*)'] + 1;

	$result = db::getInstance()->rawQuery("CREATE TEMPORARY TABLE tmp SELECT * FROM category " .
		"WHERE category_id = '" . $idx . "'");

	$result = db::getInstance()->rawQuery("UPDATE tmp SET category_id = NULL, " .
		"category_order ='" . $count . "', category_image = '', category_small_image = ''");

	$result = db::getInstance()->rawQuery("INSERT INTO category SELECT * FROM tmp");
	break;
}
?>